package com.meilai.project.mapper.media;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.media.VMediaPointDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * VIEW Mapper 接口
 * </p>
 *
 * @author 张驰
 * @since 2022-03-21
 */
@Mapper
public interface VMediaPointDetailMapper extends BaseMapper<VMediaPointDetail> {
    @Select("SELECT  " +
            "x.id " +
            ",x.`code` " +
            ",x.detail " +
            "FROM v_media_point_detail x " +
            "WHERE x.id IN " +
            "(SELECT DISTINCT a.media_point_id  " +
            "FROM worker_submit a   " +
            "WHERE a.work_order_id=#{workOrderId}  " +
            "AND a.deleted_at IS NULL AND a.flow_status IN (3,4))")
    List<VMediaPointDetail> getSubmitPointsByWorkOrderId(@Param("workOrderId") Long workOrderId);

    @Select("<script>" +
            "SELECT  " +
            "x.id " +
            ",x.`code` " +
            ",x.detail " +
            "FROM work_order_install_detail_point a " +
            "JOIN v_media_point_detail x ON a.media_point_id=x.id " +
            "JOIN media_point mp ON a.media_point_id=mp.id AND mp.building_area_id=#{buildingAreaId} " +
            "WHERE a.work_order_id=#{workOrderId} " +
            "<if test=\" submitPointIds != null and submitPointIds.size()>0 \">" +
            "AND a.media_point_id NOT IN " +
            "<foreach item=\"item\" index=\"index\" collection=\"submitPointIds\" open=\"(\" separator=\",\" close=\")\"> " +
            "#{item}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    List<VMediaPointDetail> getNotSubmitBuildingPoints(@Param("workOrderId") Long workOrderId,
                                                       @Param("buildingAreaId") Long buildingAreaId,
                                                       @Param("submitPointIds") Set<Long> submitPointIds);

    @Select("<script>" +
            "SELECT " +
            "x.id " +
            ",x.`code` " +
            ",x.detail " +
            "FROM media_point_choose_daterange_mediapoint a " +
            "JOIN bill_sale b ON b.daterange_id=a.daterange_id " +
            "JOIN work_order c ON b.id=c.bill_sale_id " +
            "JOIN v_media_point_detail x ON a.media_point_id=x.id " +
            "JOIN media_point mp ON a.media_point_id=mp.id AND mp.building_area_id=#{buildingAreaId} " +
            "WHERE c.id=#{workOrderId} " +
            "<if test=\" submitPointIds != null and submitPointIds.size()>0 \">" +
            "AND a.media_point_id NOT IN " +
            "<foreach item=\"item\" index=\"index\" collection=\"submitPointIds\" open=\"(\" separator=\",\" close=\")\"> " +
            "#{item}" +
            "</foreach>" +
            "</if>" +
            "</script>")
    List<VMediaPointDetail> getNotSubmitChoosePoints(@Param("workOrderId") Long workOrderId,
                                                     @Param("buildingAreaId") Long buildingAreaId,
                                                     @Param("submitPointIds") Set<Long> submitPointIds);
}
